import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'package:google_fonts/google_fonts.dart';
import 'package:raze/potions/raze_constant.dart';
import 'package:raze/potions/spatial_alchemy.dart';

/// 幸运植物领域 - 每日随机生成一株幸运植物
class LuckPlantRealms extends StatefulWidget {
  const LuckPlantRealms({super.key});

  @override
  State<LuckPlantRealms> createState() => _LuckPlantRealmsState();
}

class _LuckPlantRealmsState extends State<LuckPlantRealms> {
  // 幸运植物数据（示例：四叶草）
  final String _botanicalName = 'Four-leaf Clover';

  final String _plantIntroduction =
      'The four-leaf clover is a rare variety of alfalfa, native to the temperate grasslands of Europe. Typically, each plant has only three leaflets, while the four-leaf form is extremely scarce. Each leaflet carries a symbolic meaning—hope, faith, love, and luck. Its leaves are relatively delicate and soft, often glistening in the drooping grass after rain.';

  final String _symbolicMeaning =
      'Luck, reunion, and soft tenacity. People believe that finding a four-leaf clover is like encountering an unexpected tenderness in life. It reminds us that luck often hides in tiny corners.';

  final String _ecologicalKnowledge =
      'After rain, four-leaf clovers absorb water through their leaf cells and release oxygen at the same time, making the damp grass fresher. Their roots contain nitrogen, replenishing soil nutrients, which makes them natural guardians of ecological balance. Drizzle plumps up their leaf veins, and tiny water droplets form natural magnifying glasses on the leaf surface, refracting green light.';

  final String _natureMessage =
      '"Today\'s luck may not be loud. Just like that extra leaf—growing quietly, yet becoming a blessing in the ordinary greenery."';

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Container(
        width: double.infinity,
        height: double.infinity,
        decoration: const BoxDecoration(
          image: DecorationImage(
            image: AssetImage('assets/images/luck-plant-background.png'),
            fit: BoxFit.cover,
          ),
        ),
        child: SafeArea(
          bottom: false,
          child: Column(
            children: [
              // 顶部返回按钮
              _constructTopNavigationBar(),
              20.h.boxHeight,

              // 可滚动内容区域
              Expanded(
                child: SingleChildScrollView(
                  padding: EdgeInsets.symmetric(horizontal: 16.w),
                  child: Column(
                    children: [
                      // 植物图片区域（四叶草）
                      _assembleFloraVisualization(),

                      // 植物名称卡片
                      _fabricateBotanicalNameCard(),
                      16.h.boxHeight,

                      // 信息内容卡片
                      _composeInformationPanel(),
                      24.h.boxHeight,
                    ],
                  ),
                ),
              ),
            ],
          ),
        ),
      ),
    );
  }

  /// 构建顶部导航栏
  Widget _constructTopNavigationBar() {
    return Padding(
      padding: EdgeInsets.symmetric(horizontal: 16.w),
      child: Row(
        children: [
          // 返回按钮
          Container(
                width: 30.w,
                height: 30.w,
                decoration: BoxDecoration(
                  color: RazeConstants.background,
                  borderRadius: BorderRadius.circular(6.r),
                  border: Border.all(color: RazeConstants.black, width: 1.5.w),
                ),
                child: Icon(
                  Icons.chevron_left_rounded,
                  size: 24.sp,
                  color: RazeConstants.black,
                ),
              )
              .withRightBottomShadow(thickness: 1)
              .withTouchResonance(onTap: () => Get.back()),
        ],
      ),
    );
  }

  /// 组装植物可视化展示
  Widget _assembleFloraVisualization() {
    // 宽高比 233/200
    final aspectRatio = 233 / 200;
    final imageWidth = 233.w;
    final imageHeight = imageWidth / aspectRatio;

    return SizedBox(
      width: imageWidth,
      height: imageHeight,
      child: Image.asset('assets/images/luck-flower.png', fit: BoxFit.contain),
    );
  }

  /// 制作植物名称卡片
  Widget _fabricateBotanicalNameCard() {
    return Container(
      width: double.infinity,
      padding: EdgeInsets.symmetric(horizontal: 20.w, vertical: 16.h),
      decoration: BoxDecoration(
        color: RazeConstants.green,
        borderRadius: BorderRadius.circular(16.r),
        border: Border.all(color: RazeConstants.black, width: 2.w),
      ),
      child: Center(
        child: Text(_botanicalName)
            .applyTypeSize(24.sp)
            .applyTypeColor(RazeConstants.white)
            .applyBagelFatOne(
              weight: FontWeight.w400,
              shadows: [
                Shadow(
                  offset: Offset(-1.w, -1.w),
                  blurRadius: 0,
                  color: RazeConstants.black,
                ),
                Shadow(
                  offset: Offset(1.w, -1.w),
                  blurRadius: 0,
                  color: RazeConstants.black,
                ),
                Shadow(
                  offset: Offset(-1.w, 1.w),
                  blurRadius: 0,
                  color: RazeConstants.black,
                ),
                Shadow(
                  offset: Offset(1.w, 1.w),
                  blurRadius: 0,
                  color: RazeConstants.black,
                ),
                Shadow(
                  offset: Offset(0, -1.w),
                  blurRadius: 0,
                  color: RazeConstants.black,
                ),
                Shadow(
                  offset: Offset(0, 1.w),
                  blurRadius: 0,
                  color: RazeConstants.black,
                ),
                Shadow(
                  offset: Offset(-1.w, 0),
                  blurRadius: 0,
                  color: RazeConstants.black,
                ),
                Shadow(
                  offset: Offset(1.w, 0),
                  blurRadius: 0,
                  color: RazeConstants.black,
                ),
              ],
            ),
      ),
    ).withRightBottomShadow(thickness: 2);
  }

  /// 编写信息面板
  Widget _composeInformationPanel() {
    return Container(
      padding: EdgeInsets.all(16.w),
      decoration: BoxDecoration(
        color: RazeConstants.white,
        borderRadius: BorderRadius.circular(16.r),
        border: Border.all(color: RazeConstants.black, width: 1.5.w),
      ),
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          // Plant Introduction
          _generateInfoSection(
            title: '📖 Plant Introduction:',
            content: _plantIntroduction,
          ),
          16.h.boxHeight,

          // Symbolic Meaning
          _generateInfoSection(
            title: '🍃 Symbolic Meaning:',
            content: _symbolicMeaning,
          ),
          16.h.boxHeight,

          // Ecological Knowledge
          _generateInfoSection(
            title: '🌍 Ecological Knowledge:',
            content: _ecologicalKnowledge,
          ),
          16.h.boxHeight,

          // Nature Message (AI生成的)
          _generateInfoSection(
            title: '💬 Nature Message (AI-generated):',
            content: _natureMessage,
            isHighlight: true,
          ),
        ],
      ),
    ).withRightBottomShadow(thickness: 1.5);
  }

  /// 生成信息区块
  Widget _generateInfoSection({
    required String title,
    required String content,
    bool isHighlight = false,
  }) {
    return Column(
      crossAxisAlignment: CrossAxisAlignment.start,
      children: [
        // 标题行
        Row(
          children: [
            Text(
              title,
              style: TextStyle(
                fontFamily:
                    GoogleFonts.aclonica(
                      fontWeight: FontWeight.w400,
                    ).fontFamily,
              ),
            ).applyTypeSize(15.sp).applyTypeColor(RazeConstants.black),
          ],
        ),
        8.h.boxHeight,
        // 内容文本
        Container(
          padding: isHighlight ? EdgeInsets.all(12.w) : EdgeInsets.zero,
          decoration:
              isHighlight
                  ? BoxDecoration(
                    color: RazeConstants.background,
                    borderRadius: BorderRadius.circular(12.r),
                    border: Border.all(
                      color: RazeConstants.black.withOpacity(0.1),
                      width: 1.w,
                    ),
                  )
                  : null,
          child: Text(content)
              .applyTypeSize(12.sp)
              .applyTypeColor(
                isHighlight
                    ? RazeConstants.black.withOpacity(0.8)
                    : RazeConstants.black.withOpacity(0.7),
              )
              .applyNotoSans(
                weight: isHighlight ? FontWeight.w500 : FontWeight.w400,
              ),
        ),
      ],
    );
  }
}
